#include <iostream>
#include <vector>
using namespace std;
int N, M;
int sum = 0x3f3f3f3f; //常用最大值
const int k = 55;
char a[k][k];
int main() {
    cin >> N >> M;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < M; j++) {
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < N - 2; i++) // 白的区间
    {
        for(int j = i + 1; j < N - 1; j++) // 蓝的区间
        {
            int ans = 0;
            for(int k = 0; k <= i; k++) {
                for(int g = 0; g < M; g++){
                    if(a[k][g] != 'W') {
                        ans++;
                    }
                }
            }
            for(int k = i + 1; k <= j; k++) {
                for(int g = 0; g < M; g++) {
                    if(a[k][g] != 'B') {
                        ans++;
                    }
                }
            }
            for(int k = j + 1; k < N; k++) {
                for(int g = 0; g < M; g++) {
                    if(a[k][g] != 'R') {
                        ans++;
                    }
                }
            }
            sum = min(sum, ans);
        }
    }
    cout << sum;
    return 0;
}


/**
 * 这是ai优化之后的代码，效率更优
 */
#include <iostream>
#include <vector>
using namespace std;

const int INF = 0x3f3f3f3f; // 无穷大常量

int main() {
    int N, M;
    cin >> N >> M;
    
    // 动态分配输入矩阵
    vector<string> grid(N);
    for (int i = 0; i < N; ++i) {
        cin >> grid[i];
    }
    
    // 预计算每行非 W、B、R 的格子数
    vector<int> cost_white(N, 0), cost_blue(N, 0), cost_red(N, 0);
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            if (grid[i][j] != 'W') cost_white[i]++;
            if (grid[i][j] != 'B') cost_blue[i]++;
            if (grid[i][j] != 'R') cost_red[i]++;
        }
    }
    
    // 枚举白色和蓝色区域的结束行
    int min_cost = INF;
    for (int white_end = 0; white_end < N - 2; ++white_end) { // 白色区域 [0, white_end]
        for (int blue_end = white_end + 1; blue_end < N - 1; ++blue_end) { // 蓝色区域 [white_end+1, blue_end]
            int cost = 0;
            // 白色区域
            for (int i = 0; i <= white_end; ++i) {
                cost += cost_white[i];
            }
            // 蓝色区域
            for (int i = white_end + 1; i <= blue_end; ++i) {
                cost += cost_blue[i];
            }
            // 红色区域
            for (int i = blue_end + 1; i < N; ++i) {
                cost += cost_red[i];
            }
            min_cost = min(min_cost, cost);
        }
    }
    
    cout << min_cost << endl;
    return 0;
}